#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
void main()
{
    int x, y, r, mi = 369, n, m;
    for (x = 1; x <= (369 - 39) / 69; x++)
    {
        y = (369 - 69 * x) / 39;
        r = 369 - 69 * x - 39 * y;
        if (r < mi)
        {
            mi = r; n = x; m = y;
        }
    }
    cout << "n=" << n << "m=" << m << "min=" << mi << endl;
}
